<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>ColorForDiv</title>
  <style>
    div{
      width: 50px;
      height: 100px;
    }
    #redDiv{
      background-color: red;
    }

    #blueDiv{
      background-color: blue;
    }
    #yellowDiv{
      background-color: yellow;
    }
  </style>
</head>
<body>
<div id="redDiv" onmouseover="changeBGColor('red')"></div>
<div id="blueDiv" onmouseover="changeBGColor('blue')"></div>
<div id="yellowDiv" onmouseover="changeBGColor('yellow')"></div>


<script>
  function changeBGColor(color){
    //获得body标签元素对象
    let bodyObj = document.body;
    //bodyObj.bgColor=color;//通过属性设置
    //通过样式表修改样式(推荐使用)
    bodyObj.style.backgroundColor=color;
  }
</script>
</body>
</html>